{extend name="base" /}
{block name="css"}
<style>
    font{
        color: #cc0000;
    }
</style>
{/block}
{block name="content"}
<!--tab标签-->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class=""><a href="{:url('admin/dp/record')}">记录</a></li>
                <li class="layui-this">添加</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <form class="layui-form" action="{:url('admin/dp/save_record')}" method="post">
                        <div class="layui-form-item">
                            <label class="layui-form-label">分类</label>
                            <div class="layui-input-block">
                                <select name="type" lay-verify="required" lay-search="">
                                    {foreach name="type_list" item="vo"}
                                    <option value="{$vo.id}">{$vo.name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="name" value="" required  lay-verify="required" placeholder="请输入名称" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">描述</label>
                            <div class="layui-input-block">
                                <textarea placeholder="请输入描述" name="desc" class="layui-textarea"></textarea>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">图片</label>
                            <div class="layui-input-block">
                                <button type="button" class="layui-btn" id="test1">上传图片</button>
                                <div class="layui-upload-list">
                                    <img class="layui-upload-img" id="demo1" width="100" height="100">
                                    <input type="hidden" name="img" id="img" value="">
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">视频</label>
                            <div class="layui-input-block">
                                <button type="button" class="layui-btn" id="test5"><i class="layui-icon"></i>上传视频</button>
                                <div class="layui-upload-list">
                                    <input type="text" name="video" id="video" value="" class="layui-input" readonly>
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">排序</label>
                            <div class="layui-input-block">
                                <input type="text" name="sort" value="" required  lay-verify="required" placeholder="请输入排序值(越小越靠前)" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="*">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<script>
    layui.use(['form','upload'], function(){
        var form = layui.form,upload = layui.upload;

        var uploadInst = upload.render({
            elem: '#test1'
            ,url: '/admin/dp/upload'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                if(res.code == 1){
                    $('#img').val(res.data.url)
                }
                layer.msg(res.msg);
            }
            ,error: function(){
                //演示失败状态，并实现重传
            }
        });

        upload.render({
            elem: '#test5'
            ,url: '/admin/dp/upload' //此处配置你自己的上传接口即可
            ,accept: 'video' //视频
            ,done: function(res){
                if(res.code == 1){
                    $('#video').val(res.data.url)
                }
                layer.msg(res.msg);
            }
        });

        /**
         * 通用表单提交(AJAX方式)
         */
        form.on('submit(*)', function (data) {
            $.ajax({
                url: data.form.action,
                type: data.form.method,
                data: $(data.form).serialize(),
                success: function (info) {
                    if (info.code === 1) {
                        setTimeout(function () {
                            window.location.reload()
                        }, 1000);
                    }
                    layer.msg(info.msg);
                }
            });

            return false;
        });

    });
</script>
{/block}
